﻿namespace _001_Iterator;

public class BookShelfIterator : IIterator
{

    private BookShelf _bookShelf;

    private int _index;

    public BookShelfIterator(BookShelf bookShelf)
    {
        _bookShelf = bookShelf;
        _index = 0;
    }

    /// <summary>
    /// 判断后面是否还有元素
    /// 简单的通过index判断即可
    /// </summary>
    /// <returns></returns>
    public bool HasNext()
    {
        return _index < _bookShelf.GetLength();
    }

    /// <summary>
    /// 获取下一个元素
    /// </summary>
    /// <returns></returns>
    public object Next()
    {
        Book book = _bookShelf.GetBookAt(_index++);
        return book;
    }
}